package com.ayh.campusfun.controller.api.v1;

import com.ayh.campusfun.common.CommonResult;
import com.ayh.campusfun.common.core.jwt.JWTUtils;
import com.ayh.campusfun.entity.Attention;
import com.ayh.campusfun.entity.Users;
import com.ayh.campusfun.service.AttentionService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 关注表(Attention)表控制层
 *
 * @author ayh
 * @since 2021-03-20 20:42:34
 */
@RestController
@RequestMapping("attention")
public class AttentionController {
    /**
     * 服务对象
     */
    @Autowired
    private AttentionService attentionService;

    @Autowired
    private JWTUtils jwtUtils;


    @PostMapping(value = "/attentionUser",produces = "application/json")
    public CommonResult attentionUser(HttpServletRequest request ,String uid){
        Users userFromRequest = jwtUtils.getUserFromRequest(request);
        Attention attention = Attention.builder()
                .attentionId(uid)
                .uid(userFromRequest.getUid())
                .attentionStatus(1)
                .build();
        Long insert = attentionService.insert(attention);
        return CommonResult.success(insert);
    }

}
